package com.nz2004.controller;

import com.nz2004.entity.AdminUser;
import com.nz2004.entity.Menu;
import com.nz2004.entity.MyMsg;
import com.nz2004.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    @GetMapping("/queryMenu")
    @ResponseBody
    public List<Menu> queryMenuByUserId(HttpSession session){
        AdminUser user = (AdminUser) session.getAttribute("user");
        Integer userId = user.getId();
        System.out.println(userId);
        List<Menu> menus = menuService.queryMenuByUserId(userId);
        return menus;
    }

    @GetMapping("/queryMenus")
    @ResponseBody
    public MyMsg queryMenus(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "5") int limit){
        MyMsg myMsg = menuService.queryMenus(page, limit);
        return myMsg;
    }
}
